from fastapi import APIRouter
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
from fastapi.responses import HTMLResponse
from typing import Union


router = APIRouter()

@router.get("/docs", response_class=HTMLResponse)
async def custom_swagger_ui_html():
    return get_swagger_ui_html(
        openapi_url="/openapi.json",
        title="Ollama Qdrang Mongodb Ragsystem - API 文档",
        swagger_js_url="/static/swagger-ui-bundle.js",
        swagger_css_url="/static/swagger-ui.css",
        swagger_ui_parameters={
            "defaultModelsExpandDepth": -1,  # 默认不展开模型
            "deepLinking": True,  # 启用深度链接
            "displayRequestDuration": True,  # 显示请求持续时间
            "docExpansion": "none",  # 默认折叠所有接口
            "filter": True,  # 启用过滤功能
            "showExtensions": True,  # 显示扩展信息
            "showCommonExtensions": True,  # 显示通用扩展信息
            "persistAuthorization": True,  # 保持授权信息
        }
    )

@router.get("/redoc", response_class=HTMLResponse)
async def custom_redoc_html():
    return get_redoc_html(
        openapi_url="/openapi.json",
        title="Ollama Qdrang Mongodb Ragsystem  - Redoc API 文档",
        redoc_js_url="/static/redoc.standalone.js",
        with_google_fonts=False
    )
@router.get("/")
def read_root():
    return {"Hello": "World"}

@router.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}